#ifndef PERCEPTION_LIDAR_DATA_POOL_H_
#define PERCEPTION_LIDAR_DATA_POOL_H_

#include "base_data_pool.h"
#include "data_type.h"
#include <condition_variable>
#include <functional>
#include <list>
#include <memory>
#include <mutex>
#include <vector>

namespace perception
{
    class DataPool
    {
    public:
        MainData *GetMainDataPtr() { return &main_data_; }
        MainData &GetMainDataRef() { return main_data_; }

        // 当前默认五个雷达，可以少于5个，但不能多，后续如果要改再加参数改为可变的

        void SetLidarPoints(XYZI_PTR &points, double &time, int lidar_num)
        {
            std::vector<std::mutex> points_mutex(5);
            std::lock_guard<std::mutex> locker(points_mutex[lidar_num]);
            main_data_.lidar_points.point_cloud_ptr_map[lidar_num].points = points;
            main_data_.lidar_points.point_cloud_ptr_map[lidar_num].time = time;
        }
        bool GetLidarPreprocessDataInput()
        {
            std::mutex preprocess_iput_mutex;
            std::lock_guard<std::mutex> locker(preprocess_iput_mutex);
            if (main_data_.lidar_points.point_cloud_ptr_map[0].points->points.empty())
            {
                main_data_.preprocess_data_.no_ground_points.points.reset(new XYZI);
                main_data_.preprocess_data_.ground_points.points.reset(new XYZI);
                return false;
            }
            main_data_.preprocess_data_.data_in = main_data_.lidar_points;
            main_data_.preprocess_data_.no_ground_points.points.reset(new XYZI);
            main_data_.preprocess_data_.ground_points.points.reset(new XYZI);
            return true;
        }
        bool GetLidarPreprocessDataOutput()
        {
            if (main_data_.preprocess_data_.no_ground_points.points->empty())
                return false;
            return true;
        }
        bool GetLidarCellDataInput()
        {
            std::mutex lidar_cells_input_mutex;
            std::lock_guard<std::mutex> locker(lidar_cells_input_mutex);
            if (GetLidarPreprocessDataOutput())
            {
                main_data_.lidar_cells_data_.data_in.points.reset(new XYZI);
                main_data_.lidar_cells_data_.data_in = main_data_.preprocess_data_.no_ground_points;
                return true;
            }
            return false;
        }

    private:
    public:
        MainData main_data_; //

        DataPool() {}

        // BASE_DECLARE_SINGLETON(DataPool)
        BASE_HUNGRY_SINGLETON(DataPool)
    };
    // } // lidar_cell
} // perception
#endif // AVOS_MAPENGINE_DATA_POOL_H_
